﻿using Akka.Actor;
using Akka.Configuration;
using Akka.Ext.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestClientNet45
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Task.Run(async () =>
            {
                var configIni = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
                var config = ConfigurationFactory.ParseString(configIni);
                var system = ActorSystem.Create("client2", config); //root

                var akkaClient = new AkkaHttpClient(system);
                var uri = "akka.tcp://server2@localhost:2553/user/test";
                var req = new RequestInfo();
                //req.Method = RestSharp.Method.POST;
                //req.Url = "/api/get";
                //req.Url = "/api/getjson";
                req.Url = "/api/getfile";
                //req.Url = "/api/post";
                //req.Url = "/api/postbody";
                //req.Url = "/api/postfile";
                
                //req.Header.Add("token", "ancdefg123");
                //req.Cookie.Add("c", "cookiesss");
                //req.Query.Add("name", "李白post");
                //req.Form.Add("name", "小小form");
                //req.JsonBody = "{\"id\":1}";
                //req.Files.Add(new UploadFileInfo() { Name = "file", BytesData = new byte[] { 1 }, FileName = "1.jpg" });

                var res = await akkaClient.ExecuteAsync(uri, req);
                Console.WriteLine($"IsSuccess==>    {res.IsSuccess}");
                Console.WriteLine($"ErrorMessage==> {res.ErrorMessage}");
                Console.WriteLine($"Data==>         {res.Data}");
                Console.WriteLine($"ContentType==>  {res.ContentType}");
                Console.WriteLine($"DataBytes==>    {res.DataBytes?.Length}");
                Console.WriteLine($"FileName==>     {res.FileName}");
            });

            Console.ReadKey();
        }
    }
}
